package com.tenghui.common.enums;

import lombok.Getter;

import static com.tenghui.common.core.domain.AjaxResult.error;

/**
 * 销售状态枚举
 */
@Getter
public enum ListingStatus {
    OFF_SHELF("0", "下架"),
    ON_SHELF("1", "上架"),
    SOLD_OUT("2", "售罄");

    private final String code;  // 字典键值
    private final String description;  // 字典标签

    ListingStatus(String code, String description) {
        this.code = code;
        this.description = description;
    }

    /**
     * 根据描述获取枚举
     */
    public static ListingStatus getByDescription(String desc) {
        for (ListingStatus status : values()) {
            if (status.description.equals(desc)) {
                return status;
            }
        }
        throw new IllegalArgumentException("无效的状态描述：" + desc);
    }

    /**
     * 根据code获取枚举
     */
    public static ListingStatus getByCode(String code) {
        for (ListingStatus status : values()) {
            if (status.code.equals(code)) {
                return status;
            }
        }
        throw new IllegalArgumentException("无效的状态代码：" + code);
    }
}